package com.tanhua.server.interceptor;

import com.tanhua.model.domain.Character;

import java.util.*;
import java.util.stream.Collectors;

public class RandomById {

    //随机取数
    public static List random (int count,int num){

        Set set = new HashSet();

        while (set.size() != num) {
            Random random = new Random();
            int n = random.nextInt(count) + 1;
            set.add(n);
        }

        //Collections.shuffle(); // 打乱集合顺序

        List<Integer> collect = (List<Integer>) set.stream().collect(Collectors.toList());

        return collect;
    }


    public static Map<String, String> cover(List<String> list, List<Character> characters){

        Map<String, String> map = new HashMap<>();

        String characterId = null;
        double sum = 0;
        int score = 0;

        for (String s : list) {
            if(s.equals("0")){
                score = 10;
            }else if(s.equals("1")){
                score = 20;
            }else if(s.equals("2")){
                score = 30;
            }else if(s.equals("3")){
                score = 40;
            }

            sum += score;
        }

        sum = sum / list.size();//0~40

        if(10 <= sum && sum < 18){
            characterId = characters.get(0).getId().toString();
        }else if(18 <= sum && sum < 26){
            characterId = characters.get(1).getId().toString();
        }else if(26 <= sum && sum < 34){
            characterId = characters.get(2).getId().toString();
        }else if(34 <= sum && sum <= 40){
            characterId = characters.get(3).getId().toString();
        }

        map.put("characterId",characterId);
        map.put("dimensions",dimensions());
        return map;
    }

    //维度
    private static String dimensions (){

        Random random = new Random();
        int num = 0;
        StringBuilder stringBuilder = new StringBuilder();

        num = random.nextInt(30)+60;
        stringBuilder.append("外向:"+num+",");
        num = random.nextInt(30)+60;
        stringBuilder.append("判断:"+num+",");
        num = random.nextInt(30)+60;
        stringBuilder.append("抽象:"+num+",");
        num = random.nextInt(30)+60;
        stringBuilder.append("理性:"+num);

        return stringBuilder.toString();
    }
}
